package MD.NJavaUnionAd;
import android.app.Activity;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;

import com.bytedance.sdk.openadsdk.TTAdConfig;
import com.bytedance.sdk.openadsdk.TTAdConstant;
import com.bytedance.sdk.openadsdk.TTAdNative;
import com.bytedance.sdk.openadsdk.TTAdSdk;
import android.util.Log;

import MD.NJavaBase.Debug;
import MD.NJavaBase.NJavaBase;
//文档 https://www.pangle.cn/union/media/union/download/detail?id=4&osType=android
public class UnionAd {
    static String TAG = "UnionAd";

    public static void Go()
    {
        Activity context = NJavaBase.getActivity();


        String UnionAppId = "5001121";
        String UnionAppName = "APP测试媒体";
        try {
            ApplicationInfo appInfo = context.getPackageManager().getApplicationInfo(
                    context.getPackageName(), PackageManager.GET_META_DATA
            );

            UnionAppId = appInfo.metaData.getString("UnionAppId")  ;
            if(UnionAppId.length()>0 && UnionAppId.charAt(0)=='#') UnionAppId = UnionAppId.substring(1);

            UnionAppName = appInfo.metaData.getString("UnionAppName")  ;
        } catch (PackageManager.NameNotFoundException e) {

            Log.e(TAG, "UnionAd.Go error!");
            e.printStackTrace();
        }

        Log.d(TAG, "UnionAd #1");

        try {
            TTAdSdk.init(context,
                    new TTAdConfig.Builder()
                            .appId(UnionAppId)
                            .useTextureView(true) //使用TextureView控件播放视频,默认为SurfaceView,当有SurfaceView冲突的场景，可以使用TextureView
                            .appName(UnionAppName)
                            .titleBarTheme(TTAdConstant.TITLE_BAR_THEME_DARK)
                            .allowShowNotify(true) //是否允许sdk展示通知栏提示
                            .allowShowPageWhenScreenLock(true) //是否在锁屏场景支持展示广告落地页
                            .debug(Debug.ENABLE) //测试阶段打开，可以通过日志排查问题，上线时去除该调用
                           // .directDownloadNetworkType(TTAdConstant.NETWORK_STATE_WIFI, TTAdConstant.NETWORK_STATE_3G ) //允许直接下载的网络状态集合
                            .supportMultiProcess(false) //是否支持多进程，true支持
                            .build());
        }catch (Exception ex)
        {
            Log.e(TAG, ex.toString());
        }
        Log.d(TAG, "UnionAd #2");


        Log.d(TAG, "UnionAd InitEnd");
    }

    /*
    public static TTAdNative getAdNative(){

        return m_AdNative;
    }
*/

}
